package structure;

import java.util.ArrayList;

import utils.Param;

public class Coordinate {
	
	public byte x;
	public byte y;
	
	public Coordinate(String coord){
		x = (byte)((byte)coord.charAt(0) - 65);
		y = (byte)(Byte.parseByte(coord.substring(1))-1);
	}
	
	public Coordinate(byte x, byte y){
		this.x = x;
		this.y = y;
	}
	
	public boolean equals(Object o){
		Coordinate c = (Coordinate) o;
		return x == c.x && y == c.y;
	}
	
	public ArrayList<Coordinate> getNeighbours() {
		ArrayList<Coordinate> neighbours = new ArrayList<Coordinate>();

		if (x - 1 >= 0)
			neighbours.add(new Coordinate((byte) (x - 1), y));

		if (y - 1 >= 0)
			neighbours.add(new Coordinate(x, (byte) (y - 1)));

		if (x + 1 < Param.SIZE)
			neighbours.add(new Coordinate((byte) (x + 1), y));

		if (y + 1 < Param.SIZE)
			neighbours.add(new Coordinate(x, (byte) (y + 1)));

		return neighbours;
	}
	
	public String toString(){
		return Character.toString((char)(x+65))+Byte.toString((byte)(y+1));
	}
}
